package com.thirtydays.frame.module.splash

import android.os.Bundle
import androidx.core.splashscreen.SplashScreen.Companion.installSplashScreen
import coil.load
import com.blankj.utilcode.util.ThreadUtils
import com.thirtydays.frame.R
import com.thirtydays.frame.base.BaseActivity
import com.thirtydays.frame.base.NoViewModel
import com.thirtydays.frame.data.DataManager
import com.thirtydays.frame.databinding.ActivitySplashBinding
import com.thirtydays.frame.module.main.MainActivity
import com.thirtydays.frame.util.ext.pop

class SplashActivity : BaseActivity<NoViewModel, ActivitySplashBinding>() {
    override fun initCreate(savedInstanceState: Bundle?) {
        installSplashScreen()
    }

    /**
     * 本地pdf使用方式：webview.loadurl("${PDFJSuRL}")
     */
    override fun init() {
        hideToolBar()
        mViewBinding.splashAiv.load(R.drawable.splash)
//        toMainActivity(3000)
    }

    private fun toMainActivity(time: Long) {
        ThreadUtils.runOnUiThreadDelayed({
            if (DataManager.isAgree) {
                pop<MainActivity>()
            } else {
                pop<AgreeActivity>()
            }
        }, time)

        ThreadUtils.runOnUiThreadDelayed({
            finish()
        }, time + 500)
    }
}